package com.cn.crmsystem.controller.businessController;

import com.cn.crmsystem.pojo.Activity;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.ActivityService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@Api(value = "市场活动",tags ="市场活动接口API" )
public class AllActivityController {
    @Autowired
    private ActivityService activityService;
    @RequestMapping(value = "/selectActivityAll",method = RequestMethod.POST)
    @ApiOperation(value = "查询所有活动接口",notes = "业务员管理员操作",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParams({
           @ApiImplicitParam(name = "activity_id",value = "活动编号",paramType = "query",dataType = "activity",required = false),
            @ApiImplicitParam(name = "activity_name",value = "活动名称",paramType = "query",dataType = "activity",required = false),
            @ApiImplicitParam(name = "activity_creator",value = "活动创建人",paramType = "query",dataType = "activity",required = false),
            @ApiImplicitParam(name = "activity_leader",value = "活动负责人",paramType = "query",dataType = "activity",required = false),
            @ApiImplicitParam(name = "activity_type",value = "活动类型(0:广告 1：研讨会 2：电子邮件 3：营销 4：合作伙伴)",paramType = "query",dataType = "activity",required = false),
            @ApiImplicitParam(name = "activity_address",value = "活动地址",paramType = "query",dataType = "activity",required = false)
    })
    public ResultJson selectActivityAll(@RequestBody
         @ApiParam(name = "map",value = "{activity_id 活动编号(int)," +
                 "activity_name 活动名称(String)," +
                 "activity_ojects 活动对象（0：潜在客户  1：客户）(int)," +
                 "activity_creator 活动创建人(int)," +
                 "activity_leader 活动负责人(int)," +
                 "activity_type 活动类型(0:广告 1：研讨会 2：电子邮件 3：营销 4：合作伙伴)(int)," +
                 "activity_start_time 开始时间(date)," +
                 "activity_end_time 结束时间(date)," +
                 "activity_budget 活动预算(double)," +
                 "activity_address 活动地址(String)," +
                 "activity_introduce 活动简介(String)," +
                 "activity_state 状态（0:启用；1：未启用）(int)" +
                 "}") Map map){
        return activityService.selectActivityAll(map);
    }

    @RequestMapping(value = "/selectByIdActivity",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID查询活动接口",notes = "业务员管理员操作",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "活动编号",paramType = "query",dataType = "activity",required = false)
    public ResultJson selectByIdActivity(@RequestParam  Integer id){
        return activityService.selectByIdActivity(id);
    }

    @RequestMapping(value = "/addActivity",method = RequestMethod.POST)
    @ApiOperation(value = "新增活动接口",notes = "管理员新增",httpMethod = "POST",response = ResultJson.class)

    public ResultJson addActivity(@RequestBody @ApiParam(name = "activity",value = "新增活动" ,required = false) Activity activity){
        Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setUser_id(1);
        System.out.println(login);

        System.out.println(activity);
        return activityService.addActivity(activity,login);
    }


    @RequestMapping(value = "/updateByIdActivity",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID修改活动",notes = "管理员修改",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "活动编号",required = false,dataType = "activity",paramType = "query")
    public ResultJson updateByIdActivity( @ApiParam(name = "activity",value = "修改活动")Integer id ){

        return activityService.updateByIdActivity(id);
    }

    @RequestMapping(value = "/deleteByIdActivity",method = RequestMethod.POST)
    @ApiOperation(value ="根据ID删除活动接口",notes = "管理层修改",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "活动编号",required = false,dataType = "activity",paramType = "query")
    public ResultJson deleteByIdActivity(@ApiParam(name = "activity",value = "删除活动")Integer id){
        return activityService.deleteByIdActivity(id);
    }

    @RequestMapping(value = "/updateByIdActivity_introduce1",method = RequestMethod.POST)
    @ApiOperation(value ="根据ID修改启动状态",notes = "管理层修改",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "活动编号",required = false,dataType = "activity",paramType = "query")
    public ResultJson updateByIdActivity_introduce1(@ApiParam(name = "activity",value = "修改启动状态")Integer id){
        return activityService.updateByIdActivity_introduce1(id);
    }

    @RequestMapping(value = "/updateByIdActivity_introduce2",method = RequestMethod.POST)
    @ApiOperation(value ="根据ID修改禁用状态",notes = "管理层修改",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "活动编号",required = false,dataType = "activity",paramType = "query")
    public ResultJson updateByIdActivity_introduce2(@ApiParam(name = "activity",value = "修改禁用状态")Integer id){
        return activityService.updateByIdActivity_introduce2(id);
    }
}
